package com.pzl.arcgis;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.Multipoint;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.PointCollection;
import com.esri.arcgisruntime.geometry.Polygon;
import com.esri.arcgisruntime.geometry.Polyline;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;

public class CreateGeometriesActivity extends AppCompatActivity {

    MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_geometries);

        mapView = (MapView) findViewById(R.id.mapView);
        final ArcGISMap mMap = new ArcGISMap(Basemap.createTopographic());
        mapView.setMap(mMap);


        // create color and symbols for drawing graphics
        SimpleMarkerSymbol singlePointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, Color.BLUE, 20);
        SimpleMarkerSymbol MultipointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, Color.RED, 14);
        SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.CROSS, Color.CYAN, null);
        SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 3);

        // add a graphic of point, multipoint, polyline and polygon.
        GraphicsOverlay overlay = new GraphicsOverlay();
        mapView.getGraphicsOverlays().add(overlay);
        overlay.getGraphics().add(new Graphic(createPolygon(), fillSymbol));
        overlay.getGraphics().add(new Graphic(createPolyline(), lineSymbol));
        overlay.getGraphics().add(new Graphic(createMultipoint(), MultipointSymbol));
        overlay.getGraphics().add(new Graphic(createPoint(), singlePointSymbol));

        /**
         * 异步地图缩放动画,用给定的填充显示给定的几何,几何。地图比例尺和中心可能会改变。
         */
        mapView.setViewpointGeometryAsync(createEnvelope(), 64);

    }


    /**
     * 代表一个矩形区域,定义的最小和最大坐标和最小和最大坐标,和SpatialReference。信封可以选择最小和最大z -和m-values。
     * getXMin(), getXMax(), getYMin(), getYMax(), getZMin(), getZMax(), getMMin(), getMMax(), getWidth(), getHeight(), and getCenter()
     *
     * @return
     */
    private Envelope createEnvelope() {
        Envelope envelope = new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.getWgs84());
        return envelope;
    }

    /**
     * 单点
     *
     * @return
     */
    private Point createPoint() {
        Point pt = new Point(139.6859700000, 35.7529830000, SpatialReferences.getWgs84());
        return pt;
    }

    /**
     * 多点
     *
     * @return
     */
    private Multipoint createMultipoint() {
        PointCollection stateCapitalsPST = new PointCollection(SpatialReferences.getWgs84());
        stateCapitalsPST.add(116.4438250000, 39.8698460000); // Sacramento, CA
        stateCapitalsPST.add(121.4519490000, 31.1843290000); // Olympia, WA
        stateCapitalsPST.add(113.2283580000, 23.1219200000); // Salem, OR
        stateCapitalsPST.add(114.0642850000, 22.5442250000); // Carson City, NV
        Multipoint multipoint = new Multipoint(stateCapitalsPST);
        return multipoint;
    }

    /**
     * 构造线
     *
     * @return
     */
    private Polyline createPolyline() {
        PointCollection borderCAtoNV = new PointCollection(SpatialReferences.getWgs84());
        borderCAtoNV.add(115.8781080000, 28.6746130000);
        borderCAtoNV.add(113.0104300000, 28.2264310000);
        borderCAtoNV.add(114.3212370000, 30.5832670000);
        borderCAtoNV.add(115.8781080000, 28.6746130000);
        Polyline polyline = new Polyline(borderCAtoNV);
        return polyline;
    }

    /**
     * 构造一个 多边形 Polygon
     *
     * @return
     */
    private Polygon createPolygon() {
        PointCollection coloradoCorners = new PointCollection(SpatialReferences.getWgs84());
        coloradoCorners.add(112.8379550000, 28.3312800000);
        coloradoCorners.add(112.8793490000, 27.7712250000);
        coloradoCorners.add(113.1978520000, 27.7681570000);
        coloradoCorners.add(113.2553440000, 28.3587480000);
        Polygon polygon = new Polygon(coloradoCorners);
        return polygon;
    }


}
